package com.czkt.controller;

import com.czkt.pojo.Orders;
import com.czkt.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/contrRpt")
public class ContrRptController {

    @Autowired
    IOrdersService ordersService;

    @RequestMapping("/list")
    public Object list(Orders order, Model model){

        List<HashMap> mapList = ordersService.getOrderMapList(order.getOdrCustomer());

        List<HashMap> mapYear = ordersService.getOrderMapListYear(order.getOdrCustomer());



        List<Object> name = mapList.stream().map(orders->{
            return orders.get("odr_customer");
        }).collect(Collectors.toList());
        model.addAttribute("name",name);


        List<Object> money = mapList.stream().map(orders->{
            return orders.get("orderPrice");
        }).collect(Collectors.toList());

        List<Object> priceYear = mapYear.stream().map(orders->{
            return orders.get("orderPrice");
        }).collect(Collectors.toList());
        model.addAttribute("priceYear",priceYear);
        model.addAttribute("money",money);
        model.addAttribute("odrCustomer",order.getOdrCustomer());

        return "contrRpt/list";
    }
}